package butines.kraz.entity.weapon;

import butines.core.SpriteSheet;
import butines.core.math.Vector2f;
import butines.kraz.entity.Projectile;
import butines.kraz.entity.Unit;
import butines.kraz.entity.Weapon;

public class WeaponRange extends Weapon {

	private SpriteSheet sheet;

	private float speed;

	public WeaponRange() {

	}

	public float getSpeed() {
		return speed;
	}

	public void setSpeed(float speed) {
		this.speed = speed;
	}

	@Override
	public void hit(Unit attacker, Unit enemy) {

		Vector2f origin = attacker.getPosition().copy();
		Vector2f target = enemy.getPosition().copy();
					
		Projectile projectile = new Projectile();
		projectile.getForward().sub(target, origin);
		projectile.getForward().normalise();
		projectile.getPosition().set(attacker.getPosition());
		projectile.setOrigin(origin);
		projectile.setTarget(target);
		projectile.setDamage(getDamage());
		projectile.setAttacker(attacker);
		projectile.setEnemy(enemy);
		projectile.setWeapon(this);
		projectile.setMaxSpeed(getSpeed());
		projectile.setRadius(6);

		projectile.setSheet(sheet);
		projectile.getSprite().play();

		getKraz().addProjectile(projectile);

	}
	
	public SpriteSheet getSheet() {
		return sheet;
	}

	public void setSheet(SpriteSheet sheet) {
		this.sheet = sheet;
	}


}
